package com.haier.uos.springcloud.basic.config;

import com.haier.uos.springcloud.basic.job.WeatherDataSyncJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    private static final int TIME = 1800;

    //JobDetail
    @Bean
    public JobDetail weatherDataSyncJobDetail() {
        return JobBuilder.newJob(WeatherDataSyncJob.class)
                .withIdentity("weatherDataSyncJobDetail")
                .storeDurably()// 即使没有Trigger关联时，也不需要删除该JobDetail
                .build();
    }
    //Trigger
    @Bean
    public Trigger weatherDataTrigger() {
        SimpleScheduleBuilder schedBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(TIME).repeatForever();
        return TriggerBuilder.newTrigger()
                .forJob(weatherDataSyncJobDetail())
                .withSchedule(schedBuilder)
                .withIdentity("weatherDataTrigger")
                .build();
    }
}
